package com.xysl.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.xysl.api.domain.XyslMenu;
import com.xysl.api.model.XyslLoginUser;
import com.xysl.domain.dto.XyslMenuDTO;
import com.xysl.domain.vo.GartenHomeDailyVo;
import com.xysl.domain.vo.GartenHomePageVo;
import com.xysl.service.IXyslUserService;
import com.xysl.service.KindergartenService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 幼儿园主页Controller
 *
 * @author xysl
 * @date 2024-12-27
 */
@Tag(name = "xysl_幼儿园主页",description ="xysl_幼儿园主页")
@RestController
@RequestMapping("/kindergarten")
    public class KindergartenController extends BaseController
{
    @Resource
    private KindergartenService gartenService;

    @Resource
    IXyslUserService userService;



    @Operation(summary = "主页展示信息")
    @PostMapping("/homePage")
    public R<GartenHomePageVo> homePage(
            @Parameter(description = "统计数据查询周期，today-今日;week-本周;month-本月;lastMonth-上月")
            @RequestParam(required = false) String collectCycle,

            @Parameter(description = "上级菜单id")
            @RequestParam(required = false) Long menuParentId,

            @Parameter(description = "检索内容")
            @RequestParam(required = false) String searchValue)
    {
        GartenHomePageVo result = new GartenHomePageVo();
        XyslLoginUser xyslLoginUser = SecurityUtils.getXyslLoginUser();
        Long userId = xyslLoginUser.getXyslUser().getId();
        //统计数据展示
        List<GartenHomePageVo.CollectData> collectDataList = gartenService.collectData(userId,collectCycle==null?"":collectCycle);
        result.setCollectDataList(collectDataList);
        //菜单列表
        XyslMenuDTO menuDTO = new XyslMenuDTO();
        menuDTO.setUserId(userId);
        menuDTO.setParentId(menuParentId);
        List<XyslMenu> menuList = userService.queryLoginUserMenuList(menuDTO);
        result.setMenuList(menuList);
        return R.ok(result);
    }


    @Operation(summary = "主页待办数据")
    @PostMapping("/homePageDailyList")
    public R<GartenHomeDailyVo> homePageDaily(
            @Parameter(description = "检索内容")
            @RequestParam(required = false) String searchValue)
    {
        XyslLoginUser xyslLoginUser = SecurityUtils.getXyslLoginUser();
        Long userId = xyslLoginUser.getXyslUser().getId();
        GartenHomeDailyVo res = gartenService.queryDailyAndStuBirth(userId);
        return R.ok(res);
    }

}
